<template>
  <div class="warpper">
    <van-swipe :autoplay="3000" lazy-render indicator-color="#ee0a24">
      <van-swipe-item v-for="(item, index) in banner" :key="index">
        <img :src="item.imageUrl" />
      </van-swipe-item>
    </van-swipe>
    <!-- 歌单，歌手，热们mv，私人fm -->
    <div class="navigation-group">
      <div class="navigation-item" v-for="(item, index) in navigationInfo" :key="index" @click="handlerNavigation(item)">
        <div class="navigation-icon">
          <svg class="icon" aria-hidden="true">
            <use :xlink:href="item.navIcon"></use>
          </svg>
        </div>
        <span class="navigation-txt">{{ item.txt }}</span>
      </div>
    </div>
    <van-list class="rec-van-list" v-model:loading="loading" :finished="finished" finished-text="没有更多了">
      <div class="title">推荐歌单</div>
      <div class="rec-content">
        <div class="rec-list" v-for="(item, index) in recommendMusicList" :key="index">
          <van-image width="115px" height="115px" fit="cover" :src="item.coverImgUrl" />
          <div class="rec-describe">{{ item.name }}</div>
        </div>
      </div>
    </van-list>
    <van-list class="new-van-list" v-model:loading="loading" :finished="finished" finished-text="没有更多了">
      <div class="title">推荐新音乐</div>
      <div class="content" v-for="(item, index) in newSongData" :key="index" @click="handlerPlay(item)">
        <div class="new-song-item">
          <div class="songInfo">
            <span>{{ item.name }}</span>
            <p>{{ item.song.album.artists[0].name }}</p>
          </div>

          <div class="control">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-bofang"></use>
            </svg>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { bannerImg, highquality, newsong } from '@/api/indexApi.js'
export default {
  data() {
    return {
      banner: [],
      recommendMusicList: [],
      newSongData: [],
      navigationInfo: [
        { navIcon: '#icon-gedan', txt: '歌单', id: 1 },
        { navIcon: '#icon-geshou', txt: '歌手', id: 2 },
        { navIcon: '#icon-MV', txt: '热门MV', id: 3 },
        { navIcon: '#icon-yinletianchong', txt: '私人FM', id: 4 },
      ],
      recMusicPar: {
        limit: 20,
      },
      newSongPar: {
        limit: 20,
      },
    }
  },
  created() {
    this.getBanner()
    this.getRecMusicList()
    this.getNewSong()
  },
  methods: {
    getBanner() {
      //获取banner图信息
      bannerImg({ type: 0 }).then((res) => {
        if (res.data.code !== 200) return
        this.banner = res.data.banners
      })
    },
    //获取精品歌单，推荐歌单需要登录
    getRecMusicList() {
      highquality(this.recMusicPar).then((res) => {
        if (res.data.code !== 200) return
        this.recommendMusicList = res.data.playlists
      })
    },
    //获取推荐新音乐
    getNewSong() {
      newsong(this.newSongPar).then((res) => {
        console.log(res)
        this.newSongData = res.data.result
      })
    },
    //点击播放音乐
    handlerPlay(val) {
      this.$router.push({ path: '/playView', query: { id: val.id, name: val.song.album.artists[0].name } })
    },
    //点击歌单，歌手，热门mv，私人fm其中一项
    handlerNavigation(val) {
      switch (val.id) {
        case 1:
          this.$router.push({ name: 'songSheet', params: {} })
          break
        case 2:
          break
        case 3:
          break
        case 4:
          break
      }
    },
  },
}
</script>

<style lang="less" scoped>
.warpper {
  width: 100%;
  display: flex;
  align-items: center;
  flex-direction: column;
}
.van-swipe-item {
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.navigation-group {
  width: 100%;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-around;

  .navigation-item {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 10px;
    .navigation-icon {
      width: 1.2rem;
      height: 1.2rem;
      border-radius: 50%;
      background: #fef2f2;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 6px;
    }
    .navigation-txt {
      font-size: 14px;
      color: #606266;
    }
  }
}
.rec-van-list {
  width: 100%;
  height: 5rem;
  margin-top: 0.4rem;
  display: flex;

  align-items: center;
  flex-direction: column;

  .rec-content {
    display: flex;
    height: 3.8rem;
    width: 96%;
    overflow-x: scroll;
    overflow-y: hidden;
    .rec-list {
      height: 3rem;
      display: flex;
      flex-direction: column;
      margin-right: 0.3rem;
      .rec-describe {
        letter-spacing: 1px;
        line-height: 150%;
      }
    }
  }
}
.new-van-list {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  .content {
    width: 96%;
    .new-song-item {
      width: calc(100% - 0.4rem);
      height: 1.5rem;
      border-top: #ebeef5 solid 1px;
      border-bottom: #ebeef5 solid 1px;
      display: flex;
      padding: 0 0.2rem;
      .songInfo {
        flex: 3;
        height: 100%;
        flex-direction: column;
        justify-content: center;
        span {
          font-size: 14px;
          margin-bottom: 4px;
        }
        p {
          color: #909399;
        }
      }
      .control {
        flex: 1;
        height: 100%;
        align-items: center;
        justify-content: end;
      }
      .songInfo,
      .control {
        display: flex;
      }
    }
  }
}
.title {
  height: 0.8rem;
  width: 94%;
  background: #ebeef5;
  display: flex;
  align-items: center;
  padding-left: 10px;
  margin-bottom: 10px;
}
</style>